package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.AdListBO;
import com.cskaoyan.bean.pojo.MarketAd;
import com.cskaoyan.bean.vo.AdListVO;
import com.cskaoyan.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 广告管理模块
 *
 * @author chenxu
 * @since 2022/04/06 16:09
 */
@RestController
@RequestMapping("admin")
public class AdController {

    @Autowired
    AdService adService;
    //查看广告
    @RequestMapping("ad/list")
    public BaseRespVo list (AdListBO adListBO){
        AdListVO adListVO = adService.list(adListBO);
        return BaseRespVo.ok(adListVO);
    }
   //删除广告信息
    @PostMapping("ad/delete")
    public BaseRespVo delete(@RequestBody MarketAd marketAd){
         adService.delete(marketAd);
        return BaseRespVo.ok();
    }

    //修改广告信息
    @PostMapping("ad/update")
    public BaseRespVo update (@RequestBody MarketAd marketAd){
        MarketAd marketAd1 = adService.update(marketAd);
        return BaseRespVo.ok(marketAd1);
    }

    //新增广告信息
    @PostMapping("ad/create")
    public BaseRespVo create(@RequestBody MarketAd marketAd){
        if ((marketAd.getLink() == null)){
            return BaseRespVo.fail(401,"活动连接不能为空哦！请输入活动链接 -_-");
        }
        MarketAd marketAd1 = adService.create(marketAd);

        return BaseRespVo.ok(marketAd1);
    }
}
